package com.raindrop.rd.parser.match;

import com.raindrop.rd.parser.token.TokenType;
import com.raindrop.rd.util.StringUtils;

/**
 * token匹配树
 *
 * @author BillDowney
 * @date 2021/3/24 14:15
 */
public class TokenTree extends CharTree<TokenType> {

    public TokenTree() {
        super();
    }

    /**
     * 创建一个token数
     *
     * @return {@link TokenType}
     */
    public static TokenTree create() {
        TokenTree tree = new TokenTree();
        for (TokenType type : TokenType.values()) {
            if (StringUtils.isNotEmpty(type.mark)) {
                tree.add(type.mark, type);
            }
        }
        return tree;
    }

    public static void main(String[] args) {
        TokenTree tree = TokenTree.create();
        System.out.println(tree.contains("i"));
        System.out.println(tree.contains("//"));
        System.out.println(tree.contains("int"));
        System.out.println(tree.get("int"));
        System.out.println(tree.get("i"));
    }

}
